<!DOCTYPE html>
<html>



<head>
    <script>window.serq=[];StackExchange={ready:function(f){serq.push(f)}}</script>
    
    
    <title>SQL parser library for Java - Retrieve the list of table names present in a SQL statement - Stack Overflow</title>
    <link rel="shortcut icon" href="http://cdn.sstatic.net/stackoverflow/img/favicon.ico">
    <link rel="apple-touch-icon" href="http://cdn.sstatic.net/stackoverflow/img/apple-touch-icon.png">
    <link rel="search" type="application/opensearchdescription+xml" title="Stack Overflow" href="/opensearch.xml">

    
    
    
    <link rel="stylesheet" type="text/css" href="http://cdn.sstatic.net/stackoverflow/all.css?v=04e0337352b3">
    
    <link rel="canonical" href="http://stackoverflow.com/questions/5572793/sql-parser-library-for-java-retrieve-the-list-of-table-names-present-in-a-sql">
    <link rel="alternate" type="application/atom+xml" title="Feed for question 'SQL parser library for Java - Retrieve the list of table names present in a SQL statement'" href="/feeds/question/5572793">
    <meta name="title" content="SQL parser library for Java - Retrieve the list of table names present in a SQL statement - Stack Overflow">
    <link rel="image_src" href="http://sstatic.net/stackoverflow/img/apple-touch-icon.png">



    

</head>
<body class="question-page">
    <noscript><div id="noscript-padding"></div></noscript>
    <div id="notify-container"></div>
    <div id="overlay-header"></div>
    <div id="custom-header"></div>

    <div class="container">
        <div id="header">
            <div id="portalLink">
                <a class="genu" href="http://stackexchange.com" onclick="StackExchange.ready(function(){genuwine.click();});return false;">Stack Exchange</a>
            </div>
            <div id="topbar">
                <div id="hlinks">
                    <span id="hlinks-user">
                  
                  </span>
                  <span id="hlinks-nav">
                  <a href="/users/login?returnurl=%2fquestions%2f5572793%2fsql-parser-library-for-java-retrieve-the-list-of-table-names-present-in-a-sql">log in</a>
 <span class="lsep">|</span>
<a href="http://careers.stackoverflow.com">careers</a>
 <span class="lsep">|</span>

                  </span>
                  <span id="hlinks-custom">
                  <a href="http://chat.stackoverflow.com">chat</a>
 <span class="lsep">|</span>
<a href="http://meta.stackoverflow.com">meta</a>
 <span class="lsep">|</span>
<a href="/about">about</a>
 <span class="lsep">|</span>
<a href="/faq">faq</a>
                  </span>
                </div>
                <div id="hsearch">
                    <form id="search" action="/search" method="get" autocomplete="off">
                    <div>
                        <input autocomplete="off" name="q" class="textbox" placeholder="search" tabindex="1" type="text" maxlength="140" size="28" value="">
                    </div>
                    </form>
                </div>
            </div>
            <br class="cbt">
            <div id="hlogo">
                <a href="/" >Stack Overflow</a>
            </div>
            <div id="hmenus">
                <div class="nav mainnavs">
                    <ul>
                        <li class="youarehere"><a id="nav-questions" href="/questions">Questions</a></li>
                        <li><a id="nav-tags" href="/tags">Tags</a></li>
                        <li><a id="nav-users" href="/users">Users</a></li>
                        <li><a id="nav-badges" href="/badges">Badges</a></li>
                        <li><a id="nav-unanswered" href="/unanswered">Unanswered</a></li>
                    </ul>
                </div>
                <div class="nav askquestion">
                    <ul>
                        <li>
                            <a id="nav-askquestion"  href="/questions/ask">Ask Question</a>
                        </li>
                    </ul>
                </div>
            </div>
        </div>

        


        <div id="content">
            
            


<div itemscope itemtype="http://schema.org/Article">
<link itemprop="image" href="http://cdn.sstatic.net/stackoverflow/img/apple-touch-icon.png">
<div id="question-header">
    <h1 itemprop="name"><a href="/questions/5572793/sql-parser-library-for-java-retrieve-the-list-of-table-names-present-in-a-sql" class="question-hyperlink">SQL parser library for Java - Retrieve the list of table names present in a SQL statement</a></h1>
</div>
<div id="mainbar">


<div class="question" id="question" data-questionid="5572793" >

    <div class="everyonelovesstackoverflow" id="adzerk1">
    </div>

    
    <table>
    <tr>
    <td class="votecell">
        

<div class="vote">
    <input type="hidden" value="5572793">
    <a class="vote-up-off" title="This question shows research effort; it is useful and clear (click again to undo)">up vote</a>
    <span class="vote-count-post">1</span>
    <a class="vote-down-off" title="This question does not show any research effort; it is unclear or not useful (click again to undo)">down vote</a>
    <a class="star-off" href="#" title="This is a favorite question (click again to undo)">favorite</a>
    <div class="favoritecount"><b></b></div>   
 
    <a id="gp-share-5572793" class="gp-share" title="share link to this question on Google+">share [g+]</a>
    <a id="fb-share-5572793" class="fb-share" title="share link to this question on Facebook">share [fb]</a>
    <a id="twitter-share-5572793" class="twitter-share" title="share link to this question on Twitter">share [tw]</a>    
</div>

    </td>
<td class="postcell">
<div>          
    <div class="post-text" itemprop="description">
        <p>I am looking for a SQL Library that will parse an SQL statement and return some sort of Object representation of the SQL statement. My main objective is actually to be able to parse the SQL statement and retrieve the list of table names present in the SQL statement (including subqueries, joins and unions).</p>

<p>I am looking for a free library with a license business friendly (e.g. Apache license). I am looking for a library and not for an SQL Grammar. I do not want to build my own parser.</p>

<p>The best I could find so far was <a href="http://jsqlparser.sourceforge.net/home.php" rel="nofollow">JSQLParser</a>, and the <a href="http://jsqlparser.sourceforge.net/example.php" rel="nofollow">example</a> they give is actually pretty close to what I am looking for. However it fails parsing too many good queries (DB2 Database) and I'm hoping to find a more reliable library.</p>

    </div>            
    <div class="post-taglist">
        <a href="/questions/tagged/java" class="post-tag" title="show questions tagged 'java'" rel="tag">java</a> <a href="/questions/tagged/sql" class="post-tag" title="show questions tagged 'sql'" rel="tag">sql</a> <a href="/questions/tagged/parsing" class="post-tag" title="show questions tagged 'parsing'" rel="tag">parsing</a> 
    </div>
    <table class="fw">
    <tr>
    <td class="vt">
        <div class="post-menu"><a href="/q/5572793" title="short permalink to this question" id="link-post-5572793">link</a><span class="lsep">|</span><a href="/posts/5572793/edit" >improve this question</a></div>
    </td>
    <td align="right" class="post-signature">
<div class="user-info user-hover"><div class="user-action-time">edited <a href="/posts/5572793/revisions" title="show all edits to this post"><span title="2011-04-07 08:13:39Z" class="relativetime">Apr 7 '11 at 8:13</span></a></div><div class="user-gravatar32"><a href="/users/120163/ira-baxter"><div class=""><img src="http://www.gravatar.com/avatar/35e39c0fc484a47ed2345670ddc7781e?s=32&amp;d=identicon&amp;r=PG" alt="" width="32" height="32"></div></a></div><div class="user-details"><a href="/users/120163/ira-baxter">Ira Baxter</a><br><span class="reputation-score" title="reputation score 28478" dir="ltr">28.5k</span><span title="2 gold badges"><span class="badge1"></span><span class="badgecount">2</span></span><span title="34 silver badges"><span class="badge2"></span><span class="badgecount">34</span></span><span title="68 bronze badges"><span class="badge3"></span><span class="badgecount">68</span></span></div></div>    </td>
    <td class="post-signature owner">
    <div class="user-info"><div class="user-action-time">asked <span title="2011-04-06 20:52:29Z" class="relativetime">Apr 6 '11 at 20:52</span></div><div class="user-gravatar32"><a href="/users/171636/mario-duarte"><div class=""><img src="http://www.gravatar.com/avatar/e1811f29c935dcbc05443517764331cd?s=32&amp;d=identicon&amp;r=PG" alt="" width="32" height="32"></div></a></div><div class="user-details"><a href="/users/171636/mario-duarte">Mario Duarte</a><br><span class="reputation-score" title="reputation score" dir="ltr">449</span><span title="4 silver badges"><span class="badge2"></span><span class="badgecount">4</span></span><span title="15 bronze badges"><span class="badge3"></span><span class="badgecount">15</span></span></div></div>
        <br class="cbt">
        <div class="accept-rate cool" title="this user has accepted an answer for 10 of 14 eligible questions">71% accept rate</div>
    </td>
    </tr>
    </table>
</div>
</td>    </tr>


<tr>
<td class="votecell"></td>
<td>
    <div id="comments-5572793" class="comments dno">
        <table>
        <tbody>
        
            <tr><td></td><td></td></tr>
        
        </tbody>
    
        </table>
    </div>
    
    
    <div class="was-this-helpful">
        feedback
    </div>
    
</td>
</tr>    </table>    
</div>



<div id="answers">

    <a name="tab-top"></a>
    <div id="answers-header">
        <div class="subheader answers-subheader">
            <h2>2 Answers</h2>
            <div id="tabs">
                <a href="/questions/5572793/sql-parser-library-for-java-retrieve-the-list-of-table-names-present-in-a-sql?answertab=active#tab-top" title="Answers with the latest activity first">active</a>
<a href="/questions/5572793/sql-parser-library-for-java-retrieve-the-list-of-table-names-present-in-a-sql?answertab=oldest#tab-top" title="Answers in the order they were provided">oldest</a>
<a class="youarehere" href="/questions/5572793/sql-parser-library-for-java-retrieve-the-list-of-table-names-present-in-a-sql?answertab=votes#tab-top" title="Answers with the highest score first">votes</a>

            </div>
        </div>    
    </div>    


  
    <a name="5573189"></a>
    <div id="answer-5573189" class="answer"  data-answerid="5573189">
        <table>
        <tr>
        <td class="votecell">
            

<div class="vote">
    <input type="hidden" value="5573189">
    <a class="vote-up-off" title="This answer is useful (click again to undo)">up vote</a>
    <span class="vote-count-post">4</span>
    <a class="vote-down-off" title="This answer is not useful (click again to undo)">down vote</a>
<span class="vote-accepted-on" title="The question owner accepted this as the best answer Aug 25 '11 at 12:15">accepted</span> 
</div>

        </td>


<td class="answercell">
    <div class="post-text"><p>I doubt you'll find anything prewritten that you can just use. The problem is that ISO/ANSI SQL is a very complicated grammar &mdash; something like more than 600 production rules IIRC.</p>

<p>Terence Parr's <a href="http://www.antlr.org/" rel="nofollow">ANTLR parser generator</a> (Java, but can generate parsers in any one of a number of target languages) has several SQL grammars available, including a couple for PL/SQL, one for a SQL Server SELECT statement, one for mySQL, and one for ISO SQL.</p>

<p>No idea how complete/correct/up-to-date they are.</p>

<p><a href="http://www.antlr.org/grammar/list" rel="nofollow">http://www.antlr.org/grammar/list</a></p>
</div>
    <table class="fw">
    <tr>
    <td class="vt">
<div class="post-menu"><a href="/a/5573189" title="short permalink to this answer" id="link-post-5573189">link</a><span class="lsep">|</span><a href="/posts/5573189/edit" >improve this answer</a></div>    </td>
    <td align="right" class="post-signature">
<div class="user-info user-hover"><div class="user-action-time">edited <a href="/posts/5573189/revisions" title="show all edits to this post"><span title="2011-04-07 08:16:16Z" class="relativetime">Apr 7 '11 at 8:16</span></a></div><div class="user-gravatar32"><a href="/users/50476/bart-kiers"><div class=""><img src="http://www.gravatar.com/avatar/6326af218d1a113fd9a8fd9668b2d7c8?s=32&amp;d=identicon&amp;r=PG" alt="" width="32" height="32"></div></a></div><div class="user-details"><a href="/users/50476/bart-kiers">Bart Kiers</a><br><span class="reputation-score" title="reputation score 44899" dir="ltr">44.9k</span><span title="8 gold badges"><span class="badge1"></span><span class="badgecount">8</span></span><span title="45 silver badges"><span class="badge2"></span><span class="badgecount">45</span></span><span title="77 bronze badges"><span class="badge3"></span><span class="badgecount">77</span></span></div></div>    </td>
            

    <td align="right" class="post-signature">   
       

    <div class="user-info"><div class="user-action-time">answered <span title="2011-04-06 21:29:03Z" class="relativetime">Apr 6 '11 at 21:29</span></div><div class="user-gravatar32"><a href="/users/467473/nicholas-carey"><div class=""><img src="http://www.gravatar.com/avatar/28088f09ded3554a87c63320a17a9a2f?s=32&amp;d=identicon&amp;r=PG" alt="" width="32" height="32"></div></a></div><div class="user-details"><a href="/users/467473/nicholas-carey">Nicholas Carey</a><br><span class="reputation-score" title="reputation score" dir="ltr">8,652</span><span title="1 gold badge"><span class="badge1"></span><span class="badgecount">1</span></span><span title="6 silver badges"><span class="badge2"></span><span class="badgecount">6</span></span><span title="17 bronze badges"><span class="badge3"></span><span class="badgecount">17</span></span></div></div>
    </td>
    </tr>
    </table>
</td>        </tr>


<tr>
<td class="votecell"></td>
<td>
    <div id="comments-5573189" class="comments">
        <table>
        <tbody>
                    
    <tr id="comment-6340616" class="comment">
        <td></td>
        <td class="comment-text"><div><span class="comment-copy">I don&#39;t actually need a complete Object representation of the SQL statement, what I really need is to extract the names of the tables present in the SQL statement. So, as long as I can somehow get that from an existing library and as long as it correctly parses most queries, I would be happy. Writing my own parser right now is not an optin as I don&#39;t have the time for that :/</span> &ndash;&nbsp;<a href="/users/171636/mario-duarte" title="449 reputation" class="comment-user owner">Mario Duarte</a> <span class="comment-date" dir="ltr"><span title="2011-04-06 21:41:14Z">Apr 6 '11 at 21:41</span></span></div></td>
    </tr>
            
    <tr id="comment-6341590" class="comment">
        <td></td>
        <td class="comment-text"><div><span class="comment-copy">your not gonna be writing your own parser.  your gonna be using a preexisting one.  YACC is another option.</span> &ndash;&nbsp;<a href="/users/159326/aepurniet" title="187 reputation" class="comment-user">aepurniet</a> <span class="comment-date" dir="ltr"><span title="2011-04-06 23:04:29Z">Apr 6 '11 at 23:04</span></span></div></td>
    </tr>
            
    <tr id="comment-6341615" class="comment">
        <td></td>
        <td class="comment-text"><div><span class="comment-copy">antlr will let you write a code snippet to a java file every time it encounters a table element in the query.  you will use this generated java file to parse the sql, and if you wrote the code snippet and header / footer correctly in antlr, then you will just have a list of tables.</span> &ndash;&nbsp;<a href="/users/159326/aepurniet" title="187 reputation" class="comment-user">aepurniet</a> <span class="comment-date" dir="ltr"><span title="2011-04-06 23:06:23Z">Apr 6 '11 at 23:06</span></span></div></td>
    </tr>
            
    <tr id="comment-6341625" class="comment">
        <td></td>
        <td class="comment-text"><div><span class="comment-copy">i dont see how you can get a list of table names without a complete representation.  if your queries are really simplistic, then maybe you can just fake it with regular expressions.</span> &ndash;&nbsp;<a href="/users/159326/aepurniet" title="187 reputation" class="comment-user">aepurniet</a> <span class="comment-date" dir="ltr"><span title="2011-04-06 23:07:32Z">Apr 6 '11 at 23:07</span></span></div></td>
    </tr>
            
    <tr id="comment-6347659" class="comment">
        <td></td>
        <td class="comment-text"><div><span class="comment-copy">what I meant was that I don&#39;t need a very flexible library. As long as it would understand most of my queries (DB2) and would give me the names of the tables present in the query, I would be happy.</span> &ndash;&nbsp;<a href="/users/171636/mario-duarte" title="449 reputation" class="comment-user owner">Mario Duarte</a> <span class="comment-date" dir="ltr"><span title="2011-04-07 09:40:43Z">Apr 7 '11 at 9:40</span></span></div></td>
    </tr>

        </tbody>
    
        </table>
    </div>
    
    
    <div class="was-this-helpful">
        feedback
    </div>
    
</td>
</tr>    </table>
</div>

    <div class="everyonelovesstackoverflow" id="adzerk3">
    </div>

    
  
    <a name="5574887"></a>
    <div id="answer-5574887" class="answer"  data-answerid="5574887">
        <table>
        <tr>
        <td class="votecell">
            

<div class="vote">
    <input type="hidden" value="5574887">
    <a class="vote-up-off" title="This answer is useful (click again to undo)">up vote</a>
    <span class="vote-count-post">3</span>
    <a class="vote-down-off" title="This answer is not useful (click again to undo)">down vote</a>
 
</div>

        </td>


<td class="answercell">
    <div class="post-text"><p>You needn't reinvent the wheel, there is already such a reliable SQL parser library there, (it's commerical, not free), and this article shows how to retrieve the list of table names present in the SQL statement (including subqueries, joins and unions) that is exactly what you are looking for.</p>

<p><a href="http://www.dpriver.com/blog/list-of-demos-illustrate-how-to-use-general-sql-parser/get-columns-and-tables-in-sql-script/" rel="nofollow">http://www.dpriver.com/blog/list-of-demos-illustrate-how-to-use-general-sql-parser/get-columns-and-tables-in-sql-script/</a></p>

<p>This SQL parser library supports Oracle, SQL Server, DB2, MySQL, Teradata and ACCESS.</p>
</div>
    <table class="fw">
    <tr>
    <td class="vt">
<div class="post-menu"><a href="/a/5574887" title="short permalink to this answer" id="link-post-5574887">link</a><span class="lsep">|</span><a href="/posts/5574887/edit" >improve this answer</a></div>    </td>
            

    <td align="right" class="post-signature">   
       

    <div class="user-info"><div class="user-action-time">answered <span title="2011-04-07 01:24:42Z" class="relativetime">Apr 7 '11 at 1:24</span></div><div class="user-gravatar32"><a href="/users/651199/james"><div class=""><img src="http://www.gravatar.com/avatar/eeddf4ca7bdafa37ab025068efdc7302?s=32&amp;d=identicon&amp;r=PG" alt="" width="32" height="32"></div></a></div><div class="user-details"><a href="/users/651199/james">James</a><br><span class="reputation-score" title="reputation score" dir="ltr">31</span><span title="1 bronze badge"><span class="badge3"></span><span class="badgecount">1</span></span></div></div>
    </td>
    </tr>
    </table>
</td>        </tr>


<tr>
<td class="votecell"></td>
<td>
    <div id="comments-5574887" class="comments">
        <table>
        <tbody>
                    
    <tr id="comment-6347746" class="comment">
        <td></td>
        <td class="comment-text"><div><span class="comment-copy">This does exactly what I am looking for. However, as I said in my question, I can only consider free libraries (although I&#39;m under the impression that&#39;s not going to happen :/) as this is just a prototype. Nonetheless, thank you! It&#39;s good to know that at least there&#39;s a good commercial library that does exactly what I need, and maybe later I would be allowed to use it.</span> &ndash;&nbsp;<a href="/users/171636/mario-duarte" title="449 reputation" class="comment-user owner">Mario Duarte</a> <span class="comment-date" dir="ltr"><span title="2011-04-07 09:46:48Z">Apr 7 '11 at 9:46</span></span></div></td>
    </tr>

        </tbody>
    
        </table>
    </div>
    
    
    <div class="was-this-helpful">
        feedback
    </div>
    
</td>
</tr>    </table>
</div>
    <a name='new-answer'></a>
    <form id="post-form" action="/questions/5572793/answer/submit" method="post"  class="post-form">
        <h2 class="space">Your Answer</h2>




<div id="post-editor" class="post-editor">  

    
    <div class="wmd-container">
        <div id="wmd-button-bar" class="wmd-button-bar"></div>
        <textarea id="wmd-input" class="wmd-input" name="post-text" cols="92" rows="15" tabindex="101"></textarea>
    </div>

    <div class="fl" style="margin-top: 8px; height:24px;">&nbsp;</div>
    <div id="draft-saved" class="draft-saved community-option fl" style="margin-top: 8px; height:24px; display:none;">draft saved</div>

    <div id="draft-discarded" class="draft-discarded community-option fl" style="margin-top: 8px; height:24px; display:none;">draft discarded</div>



    <div id="wmd-preview" class="wmd-preview"></div>
    <div></div>
    <div class="edit-block">
        <input id="fkey" name="fkey" type="hidden" value="61146190b0be91aabc9d45f0a5888a60">
        <input id="author" name="author" type="text">
    </div>
</div>   
    <div class="form-item">
        <table>
        <tr>
        <td class="vm open-id-login">
            <a id="login-link" style="font-size: 200%; margin-left: 30px;" href="/users/login?returnurl=%2fquestions%2f5572793%2fsql-parser-library-for-java-retrieve-the-list-of-table-names-present-in-a-sql">log in</a>
            <script type="text/javascript">
                StackExchange.ready(function () {
                    StackExchange.helpers.onClickDraftSave('#login-link');
                });
            </script>
        </td>

    
        <td class="orcell">
            <div class="orword">or</div>
            <div class="orline"></div>
        </td>
        <td class="vm">
            <div>
                <label for="display-name">Name</label>
                <input id="display-name" name="display-name" type="text" size="30" maxlength="30" value="" tabindex="105">
            </div>
            <div>
                <label for="m-address">Email</label>
                <input id="m-address" name="m-address" type="text" size="40" maxlength="100" value="" tabindex="106">
                <span class="edit-field-overlay">required, but never shown</span>
            </div>
            <div>
                <label for="home-page">Home Page</label>
                <input id="home-page" name="home-page" type="text" size="40" maxlength="200" value="" tabindex="107">
            </div>
        </td>
    
        </tr>
        </table>
    </div>
               
        <div class="form-submit cbt">
            <input id="submit-button" type="submit" value="Post Your Answer" tabindex="110">
            <a href="#" class="discard-answer dno">discard</a>
        </div>
    </form>




        <h2 class="bottom-notice">
                Not the answer you're looking for? 
            Browse other questions tagged <a href="/questions/tagged/java" class="post-tag" title="show questions tagged 'java'" rel="tag">java</a> <a href="/questions/tagged/sql" class="post-tag" title="show questions tagged 'sql'" rel="tag">sql</a> <a href="/questions/tagged/parsing" class="post-tag" title="show questions tagged 'parsing'" rel="tag">parsing</a> 
                or <a href="/questions/ask">ask your own question</a>.
        </h2>
</div>
</div>
<div id="sidebar">



     <script type="text/javascript">
        window.showNewUser = true;
            
                (function(){
                    var cs = window.sessionStorage && window.sessionStorage['tNewsletter'];
                    var m = /:\/\/([^\/]*)/.exec(document.referrer);
                    var h = {'www.reddit.com':1,'news.ycombinator.com':1};
                    if(window.sessionStorage && (cs || (m && m.length == 2 && h[m[1]]))){
                        showNewUser = false;
                        StackExchange.ready(function(){
                            StackExchange.newsletterAd.loader(m[1], cs);
                        });
                    }
                    if (window.localStorage && showNewUser){
                        var c = parseInt(localStorage['nuCounter'],10); 
                        c = isNaN(c) ? 1 : c+1;
                        window.localStorage['nuCounter'] = c; 
                        showNewUser = c < 10;
                    }
                })()
            
     </script>
    <div class="module newuser newuser-greeting" id="newuser-box" style="display:none;">
        <h4>Hello World!</h4>
        <div>
            <p><p>This is a collaboratively edited question and answer site for <b>professional and enthusiast programmers</b>. It's 100% free, no registration required.</p></p>
            <p class="ar"><a href="/about?mnu=1">about &raquo;</a>&nbsp;&nbsp;&nbsp;<a href="/faq?mnu=1">faq &raquo;</a>
            </p>
        </div>
    </div>
     <script type="text/javascript">
        if (showNewUser) {
            document.getElementById('newuser-box').style.display = '';
        }
     </script>
    <div class="module question-stats">
        <p class="label-key">tagged</p>
        <div class="tagged"><a href="/questions/tagged/java" class="post-tag" title="show questions tagged 'java'" rel="tag">java</a>&nbsp;<span class="item-multiplier"><span class="item-multiplier-x">&times;</span>&nbsp;<span class="item-multiplier-count">246109</span></span><br>
<a href="/questions/tagged/sql" class="post-tag" title="show questions tagged 'sql'" rel="tag">sql</a>&nbsp;<span class="item-multiplier"><span class="item-multiplier-x">&times;</span>&nbsp;<span class="item-multiplier-count">80370</span></span><br>
<a href="/questions/tagged/parsing" class="post-tag" title="show questions tagged 'parsing'" rel="tag">parsing</a>&nbsp;<span class="item-multiplier"><span class="item-multiplier-x">&times;</span>&nbsp;<span class="item-multiplier-count">10983</span></span><br>
</div>
        <table id="qinfo">
            <tr>
                <td><p class="label-key">asked</p></td>
                <td style="padding-left:10px"><p class="label-key" title="2011-04-06 20:52:29Z"><b>1 year ago</b></p></td>
            </tr>
            <tr>
                <td><p class="label-key">viewed</p></td>

                <td style="padding-left:10px"><p class="label-key"><b>1,110 times</b></p></td>
            </tr>
            <tr>
                <td><p class="label-key">active</p></td>
                <td style="padding-left:10px"><p class="label-key"><b><a href="?lastactivity" class="lastactivity-link" title="2011-04-07 08:16:16Z">1 year ago</a></b></p></td>
            </tr>
        </table>
    </div>

    
        <script type="text/javascript">
            var scriptSrc = "http://engine2.adzerk.net/z/8277/adzerk1_2_4_43,adzerk2_2_17_45,adzerk3_2_4_44?keywords=java,sql,parsing";
            if (document.referrer) {
                if (/\?/.test(scriptSrc))
                    scriptSrc += "&";
                else
                    scriptSrc += "?";
                scriptSrc += "xReferrer=" + document.referrer;
            }
            StackExchange.ready(function(){var z = document.createElement("script"); z.type = "text/javascript"; z.async = "true"; z.src = scriptSrc; var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(z, s);});
        </script>
    
    <div class="everyonelovesstackoverflow" id="adzerk2">
    </div>

    
    <div id="hireme">
        <script type="text/javascript">
            var careers_adurl="http://careers.stackoverflow.com/gethired/js",careers_cssurl="http://cdn.sstatic.net/careers/gethired/sidebar.chirp.min.css?36bf13",careers_leaderboardcssurl="http://cdn.sstatic.net/careers/gethired/ninja.min.css?36bf13",careers_companycssurl="http://cdn.sstatic.net/careers/gethired/company",careers_adselector="div.hireme, div#hireme";StackExchange.ready(function(){$.ajax({url:"http://cdn.sstatic.net/careers/gethired/loader.min.js?36bf13",dataType:"script",cache:true})});
        </script>
    </div>

      

    <div class="module sidebar-linked">
    <h4 id="h-linked">Linked</h4>
    <div class="linked">
    <div class="spacer">
<a href="/questions/7308083/parsing-sql-table-definition-using-regular-expression-in-java" class="question-hyperlink">Parsing SQL table definition using regular expression in Java</a>
</div>

    </div>
    </div>
    <div class="module sidebar-related">
    <h4 id="h-related">Related</h4>
    <div class="related">
    <div class="spacer">
<a href="/questions/56677/is-there-a-way-to-parser-a-sql-query-to-pull-out-the-column-names-and-table-name" class="question-hyperlink">Is there a way to parser a SQL query to pull out the column names and table names?</a>
</div>
<div class="spacer">
<a href="/questions/660609/sql-parser-library-for-java" class="question-hyperlink">SQL parser library for Java</a>
</div>
<div class="spacer">
<a href="/questions/1147212/sql-parser-in-c" class="question-hyperlink">SQL parser in C</a>
</div>
<div class="spacer">
<a href="/questions/3530736/parsing-and-modification-of-sql-statements-in-java" class="question-hyperlink">Parsing and modification of SQL statements in Java</a>
</div>
<div class="spacer">
<a href="/questions/4060475/parsing-sql-create-table-statement-using-jquery" class="question-hyperlink">Parsing SQL CREATE TABLE statement using jQuery?</a>
</div>
<div class="spacer">
<a href="/questions/4161071/parsing-sql-statements-get-column-name-used-where-conditions-etc-in-net" class="question-hyperlink">Parsing SQL statements ( get Column name used , where conditions etc ) in .NET</a>
</div>
<div class="spacer">
<a href="/questions/4181931/how-to-parse-html-tag-using-dom-parser-in-java" class="question-hyperlink">how to parse html tag using dom parser in java</a>
</div>
<div class="spacer">
<a href="/questions/4348383/expression-language-to-sql-where-clause-transformations" class="question-hyperlink">Expression language to SQL where clause transformations?</a>
</div>
<div class="spacer">
<a href="/questions/4429230/how-to-parse-from-sql-time-string-to-java-sql-time" class="question-hyperlink">How to parse from SQL Time (String) to java.sql.Time?</a>
</div>
<div class="spacer">
<a href="/questions/4683773/java-string-to-date-convert-null-writing-to-sql-database-issue" class="question-hyperlink">Java string to date convert null, writing to SQL database issue</a>
</div>
<div class="spacer">
<a href="/questions/5183784/which-html-dom-parser-library-for-java-is-best" class="question-hyperlink">Which html DOM parser library for Java is best?</a>
</div>
<div class="spacer">
<a href="/questions/5243673/java-org-w3c-dom-is-there-a-java-parser-library" class="question-hyperlink">Java org.w3c.dom : is there a Java parser library?</a>
</div>
<div class="spacer">
<a href="/questions/5341322/algorithm-to-extract-the-underlying-table-names-of-a-sql-query" class="question-hyperlink">Algorithm to extract the underlying table names of a SQL Query</a>
</div>
<div class="spacer">
<a href="/questions/5881893/need-java-api-to-parse-sql-statements" class="question-hyperlink">Need java API to parse SQL statements</a>
</div>
<div class="spacer">
<a href="/questions/6008839/bison-flex-sql-parser" class="question-hyperlink">Bison + Flex SQL parser</a>
</div>
<div class="spacer">
<a href="/questions/6353879/parser-to-parse-an-sql-query-and-return-the-column-names-and-the-corresponding" class="question-hyperlink">Parser to parse an SQL query and return the column name&#39;s and the corresponding table name in Java</a>
</div>
<div class="spacer">
<a href="/questions/7294808/how-to-build-your-own-sql-parser" class="question-hyperlink">How to build your own SQL parser?</a>
</div>
<div class="spacer">
<a href="/questions/7487760/parse-sql-query-in-java-with-utf-8-support" class="question-hyperlink">Parse SQL query in Java with UTF-8 support</a>
</div>
<div class="spacer">
<a href="/questions/7857753/i-need-sql-parser-for-my-own-database-implementation" class="question-hyperlink">I need sql parser for my own database implementation</a>
</div>
<div class="spacer">
<a href="/questions/8096083/are-there-any-alternatives-to-gsp-general-sql-parser" class="question-hyperlink">Are there any alternatives to GSP (General SQL Parser)?</a>
</div>
<div class="spacer">
<a href="/questions/8298350/rewriting-sql-statements-to-prepared-statements-in-java" class="question-hyperlink">Rewriting SQL statements to prepared statements in Java</a>
</div>
<div class="spacer">
<a href="/questions/8531293/parse-sql-file-with-java-and-get-statements-and-comments" class="question-hyperlink">Parse SQL file with Java and get statements and comments</a>
</div>
<div class="spacer">
<a href="/questions/9166207/is-there-a-java-lib-that-can-evaluate-sql-style-date-functions-from-a-string" class="question-hyperlink">Is there a Java lib that can evaluate SQL style date functions from a String?</a>
</div>
<div class="spacer">
<a href="/questions/10188284/i-want-to-get-parameters-from-sql-where-statement" class="question-hyperlink">I want to get parameters from sql where statement</a>
</div>
<div class="spacer">
<a href="/questions/10202185/parser-for-sql-in-java" class="question-hyperlink">parser for sql in java</a>
</div>

    </div>
    </div>
</div>

<div id="feed-link">
    <div id="feed-link-text"><a href="/feeds/question/5572793" title="feed of this question and its answers"><span class="feed-icon"></span>question feed</a></div>
</div>

<noscript>
    <div><img src="/posts/5572793/ivc/7444" class="dno" alt="" width="0" height="0"></div>
</noscript><div style="display:none" id="prettify-lang">default</div></div>
        </div>
    </div>
    <div id="footer">
        <div class="footerwrap">
            <div id="footer-menu">
                <a href="/about">about</a> |
                <a href="/faq">faq</a> |
                <a href="http://blog.stackexchange.com?blb=1">blog</a> |
                    <a href="http://chat.stackoverflow.com">chat</a> |
                <a href="http://data.stackexchange.com">data</a> |
                <a href="http://blog.stackoverflow.com/category/podcasts/">podcast</a> |
                <a href="http://shop.stackexchange.com/">shop</a> |
                <a href="http://stackexchange.com/legal">legal</a> |
                <a href="http://engine.adzerk.net/redirect/0/2776/2751/0/4de3c60f719c4dfcb1a57531c7050090/0">advertising info</a> |

                <a onclick="StackExchange.switchMobile('on', '/questions/5572793/sql-parser-library-for-java-retrieve-the-list-of-table-names-present-in-a-sql')">mobile</a> |

                <b><a href="mailto:team@stackoverflow.com">contact us</a></b>
                  | <b><a href="http://meta.stackoverflow.com">feedback</a></b>
                <div id="footer-sites">
                    
                        <span style="color:#FE7A15;font-size:140%">&#9632;</span>&nbsp;<a href="http://stackoverflow.com">stackoverflow.com</a>&nbsp; 
                        <span style="color:#FE7A15;font-size:140%">&#9632;</span>&nbsp;<a href="http://stackapps.com">api/apps</a>&nbsp; 
                        <span style="color:#FE7A15;font-size:140%">&#9632;</span>&nbsp;<a href="http://careers.stackoverflow.com">careers</a>&nbsp; 
                        <span style="color:#E8272C;font-size:140%">&#9632;</span>&nbsp;<a href="http://serverfault.com">serverfault.com</a>&nbsp; 
                        <span style="color:#00AFEF;font-size:140%">&#9632;</span>&nbsp;<a href="http://superuser.com">superuser.com</a>&nbsp; 
                        <span style="color:#969696;font-size:140%">&#9632;</span>&nbsp;<a href="http://meta.stackoverflow.com">meta</a>&nbsp; 
                        <span style="color:#46937D;font-size:140%">&#9632;</span>&nbsp;<a href="http://area51.stackexchange.com">area&nbsp;51</a>&nbsp; 
                        <span style="color:#C0D0DC;font-size:140%">&#9632;</span>&nbsp;<a href="http://webapps.stackexchange.com">webapps</a>&nbsp; 
                        <span style="color:#000000;font-size:140%">&#9632;</span>&nbsp;<a href="http://gaming.stackexchange.com">gaming</a>&nbsp; 
                        <span style="color:#dd4814;font-size:140%">&#9632;</span>&nbsp;<a href="http://askubuntu.com">ubuntu</a>&nbsp; 
                        <span style="color:#9ce4fe;font-size:140%">&#9632;</span>&nbsp;<a href="http://webmasters.stackexchange.com">webmasters</a>&nbsp; 
                        <span style="color:#cf4d3f;font-size:140%">&#9632;</span>&nbsp;<a href="http://cooking.stackexchange.com">cooking</a>&nbsp; 
                        <span style="color:#f4f28d;font-size:140%">&#9632;</span>&nbsp;<a href="http://gamedev.stackexchange.com">game development</a>&nbsp; 
                        <span style="color:#0f3559;font-size:140%">&#9632;</span>&nbsp;<a href="http://math.stackexchange.com">math</a>&nbsp; 
                        <span style="color:#f2f2f2;font-size:140%">&#9632;</span>&nbsp;<a href="http://photo.stackexchange.com">photography</a>&nbsp; 
                        <span style="color:#037187;font-size:140%">&#9632;</span>&nbsp;<a href="http://stats.stackexchange.com">stats</a>&nbsp; 
                        <span style="color:#f1e7cc;font-size:140%">&#9632;</span>&nbsp;<a href="http://tex.stackexchange.com">tex</a>&nbsp; 
                        <span style="color:#e1cdae;font-size:140%">&#9632;</span>&nbsp;<a href="http://english.stackexchange.com">english</a>&nbsp; 
                        <span style="color:#a2d9f6;font-size:140%">&#9632;</span>&nbsp;<a href="http://cstheory.stackexchange.com">theoretical cs</a>&nbsp; 
                        <span style="color:#1b3e6c;font-size:140%">&#9632;</span>&nbsp;<a href="http://programmers.stackexchange.com">programmers</a>&nbsp; 
                        <span style="color:#293a5d;font-size:140%">&#9632;</span>&nbsp;<a href="http://unix.stackexchange.com">unix</a>&nbsp;
                        <span style="color:#bec0cb;font-size:140%">&#9632;</span>&nbsp;<a href="http://apple.stackexchange.com">apple</a>&nbsp;
                        <span style="color:#939185;font-size:140%">&#9632;</span>&nbsp;<a href="http://wordpress.stackexchange.com">wordpress</a>&nbsp;
                        <span style="color:#ebf5f5;font-size:140%">&#9632;</span>&nbsp;<a href="http://physics.stackexchange.com">physics</a>&nbsp;
                        <span style="color:#4176ab;font-size:140%">&#9632;</span>&nbsp;<a href="http://diy.stackexchange.com">home&nbsp;improvement</a>&nbsp;
                        <span style="color:#d1d8d7;font-size:140%">&#9632;</span>&nbsp;<a href="http://gis.stackexchange.com">gis</a>&nbsp;
                        <span style="color:#e5e2d3;font-size:140%">&#9632;</span>&nbsp;<a href="http://electronics.stackexchange.com">electronics</a>&nbsp;
                        <span style="color:#a4c639;font-size:140%">&#9632;</span>&nbsp;<a href="http://android.stackexchange.com">android</a>&nbsp;
                        <span style="color:#2e4e60;font-size:140%">&#9632;</span>&nbsp;<a href="http://security.stackexchange.com">security</a>&nbsp;
                        <span style="color:#45bcb5;font-size:140%">&#9632;</span>&nbsp;<a href="http://bicycles.stackexchange.com">bicycles</a>&nbsp;
                        <span style="color:#00adee;font-size:140%">&#9632;</span>&nbsp;<a href="http://dba.stackexchange.com">dba</a>&nbsp;
                        <span style="color:#2edaf0;font-size:140%">&#9632;</span>&nbsp;<a href="http://drupal.stackexchange.com">drupal</a>&nbsp;
                        <span style="color:#213951;font-size:140%">&#9632;</span>&nbsp;<a href="http://sharepoint.stackexchange.com">sharepoint</a>&nbsp;
                        <span style="color:#73abb3;font-size:140%">&#9632;</span>&nbsp;<a href="http://scifi.stackexchange.com">scifi &amp; fantasy</a>&nbsp;
                        <span style="color:#23629F;font-size:140%">&#9632;</span>&nbsp;<a href="http://ux.stackexchange.com">user experience</a>&nbsp;
                        <span style="color:#faff72;font-size:140%">&#9632;</span>&nbsp;<a href="http://skeptics.stackexchange.com">skeptics</a>&nbsp;
                        <span style="color:#623121;font-size:140%">&#9632;</span>&nbsp;<a href="http://rpg.stackexchange.com">rpg</a>&nbsp;
                        <span style="color:#e4be88;font-size:140%">&#9632;</span>&nbsp;<a href="http://judaism.stackexchange.com">judaism</a>&nbsp;
                </div>
            </div>
            <div id="footer-flair">
                <a class="peer1" href="http://www.peer1.com/stackoverflow"></a>  
	            <a href="http://creativecommons.org/licenses/by-sa/3.0/" class="cc-wiki-link"></a>
                <div id="svnrev">rev 2012.5.14.2564</div>
            </div>
            <div id="copyright">
                site design / logo &copy; 2012 stack exchange inc; 
                user contributions licensed under <a href="http://creativecommons.org/licenses/by-sa/3.0/" rel="license">cc-wiki</a> with <a href="http://blog.stackoverflow.com/2009/06/attribution-required/" rel="license">attribution required</a>
            </div>
            

        </div>
    </div>
    
    <noscript>
        <div id="noscript-warning">Stack Overflow works best with JavaScript enabled<img src="http://pixel.quantserve.com/pixel/p-c1rF4kxgLUzNc.gif" alt="" class="dno"></div>
    </noscript>
    <script type="text/javascript">var _gaq=_gaq||[];_gaq.push(['_setAccount','UA-5620270-1']);
        _gaq.push(['_setCustomVar', 1, 'tags', '|java|sql|parsing|']); 
_gaq.push(['_trackPageview']);
    var _qevents = _qevents || [];
    (function(){
        var s=document.getElementsByTagName('script')[0];
        var ga=document.createElement('script');
        ga.type='text/javascript';
        ga.async=true;
        ga.src='http://www.google-analytics.com/ga.js';
        s.parentNode.insertBefore(ga,s);
        var sc=document.createElement('script');
        sc.type='text/javascript';
        sc.async=true;
        sc.src='http://edge.quantserve.com/quant.js'; 
        s.parentNode.insertBefore(sc,s);
    })();
    </script>
    <script type="text/javascript">
        _qevents.push({ qacct: "p-c1rF4kxgLUzNc" });
    </script>    
    
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script><script type="text/javascript" src="http://cdn.sstatic.net/js/stub.js?v=b1412a85d724"></script>    <script type="text/javascript">
        
        StackExchange.ready(function () {

            StackExchange.question.init({showAnswerHelp:true,totalCommentCount:0,shownCommentCount:0,highlightColor:'#F4A83D',backgroundColor:'#FFF',questionId:5572793});

            styleCode();

                StackExchange.realtime.subscribeToQuestion('1', '5572793');
        });
    </script>    <script type="text/javascript">
        StackExchange.init({"stackAuthUrl":"https://stackauth.com","serverTime":1337099239,"styleCode":true,"enableUserHovercards":true,"site":{"name":"Stack Overflow","description":"Q&A for professional and enthusiast programmers"},"user":{"isAnonymous":true,"fkey":"61146190b0be91aabc9d45f0a5888a60","inboxUnviewedCount":-1}});
        StackExchange.using.setCacheBreakers({"js/prettify-full.js":"4ed9aa4b8d0e","js/moderator.js":"8c49fc268737","js/full-anon.js":"a4ea02603096","js/full.js":"5787e9ad9de3","js/wmd.js":"dcfaf6cb7e9c","js/third-party/jquery.autocomplete.min.js":"e5f01e97f7c3","js/mobile.js":"449beeb044d8","js/help.js":"fc9fb0517db2","js/tageditor.js":"c1ba807b32aa","js/tageditornew.js":"bd66fabe1c71","js/inline-tag-editing.js":"be882e188985","js/revisions.js":"8c6bcd93b7fe","js/suggested-edits.js":"d8960487bb7f","js/probes.js":"beb933322ff0"});
        
    </script>    <script type="text/javascript">
        StackExchange.ready(function () {
            var shareUrl = 'http%3a%2f%2fstackoverflow.com%2fq%2f5572793';
            var shareMsg = 'SQL+parser+library+for+Java+-+Retrieve+the+list+of+table+names+present+in+a+SQL+statement';
            
            StackExchange.share.gplus($('#gp-share-5572793'), shareUrl, shareMsg) ;
            StackExchange.share.facebook($('#fb-share-5572793'), shareUrl, shareMsg);
            StackExchange.share.twitter($('#twitter-share-5572793'), shareUrl, shareMsg);
        });
    </script><script type="text/javascript">
    StackExchange.ready(function() {
        initTagRenderer("".split(" "), "".split(" "));
         
        prepareEditor({
            heartbeatType: 'answer',
            bindNavPrevention: true,
            postfix: "",
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
        });
        
    });  
</script><script type="text/javascript">
StackExchange.ready(function(){$.get('/posts/5572793/ivc/7444');});
</script>
    
</body>
</html>